package com.sssre.business.controller;

import com.sssre.business.domain.TestDriveInfo;
import com.sssre.business.service.ITestDriveInfoService;
import com.sssre.common.core.controller.BaseController;
import com.sssre.common.core.domain.AjaxResult;
import com.sssre.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 浪兎兎
 * @create 2025-05-14-8:51
 */
@RestController
@RequestMapping("/business/info")
public class TestDriveInfoController extends BaseController {
    @Autowired
    private ITestDriveInfoService testDriveInfoService;

    /**
     * 查询试驾预约列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TestDriveInfo testDriveInfo) {
        startPage();
        List<TestDriveInfo> list = testDriveInfoService.selectList(testDriveInfo);
        return getDataTable(list);
    }

    /**
     * 新增试驾预约
     */
    @PostMapping
    public AjaxResult add(@RequestBody TestDriveInfo testDriveInfo) {
        return toAjax(testDriveInfoService.add(testDriveInfo));
    }

    /**
     * 修改试驾预约
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TestDriveInfo testDriveInfo) {
        return toAjax(testDriveInfoService.edit(testDriveInfo));
    }

    /**
     * 查询试驾预约详细
     */
    @GetMapping("/{id}")
    public AjaxResult one(@PathVariable Long id) {
        return AjaxResult.success(testDriveInfoService.selectOneById(id));
    }

    /**
     * 删除试驾预约
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        return toAjax(testDriveInfoService.delete(id));
    }

    /**
     * 反馈
     */
    @PatchMapping(headers = "cmd=feedback")
    public AjaxResult feedback(@RequestBody TestDriveInfo testDriveInfo) {
        return toAjax(testDriveInfoService.feedback(testDriveInfo));
    }

    /**
     * 返回有效的可用时间范围
     */
    @GetMapping("/effectiveTime")
    public AjaxResult effectiveTime(TestDriveInfo testDriveInfo) {
        return AjaxResult.success(testDriveInfoService.effectiveTime(testDriveInfo.getID(), testDriveInfo.getAppointmentDate()));
    }
}
